﻿<%@ Page Title="" Language="C#" MasterPageFile="~/System/System.master" AutoEventWireup="true" CodeFile="FileManager.aspx.cs" Inherits="System_Pages_Content_FileManager" EnableEventValidation="false" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="~/System/Controls/FieldTemplates/SinglelineText.ascx" TagPrefix="ucc" TagName="SinglelineText" %>
<%@ Register Src="~/System/Controls/FieldTemplates/MessageText.ascx" TagPrefix="ucc" TagName="MessageText" %>
<%@ Register Src="~/System/Controls/FieldTemplates/Boolean.ascx" TagPrefix="ucc" TagName="Boolean" %>
<%@ Register Src="~/System/Controls/FieldTemplates/HyperLink.ascx" TagPrefix="ucc" TagName="HyperLink" %>
<%@ Register Src="~/System/Controls/Common/FileManagerTreeView.ascx" TagPrefix="ucc" TagName="FileManager_TreeView" %>
<%@ Register Src="~/System/Controls/Common/MessageBox.ascx" TagPrefix="ucc" TagName="MessageBox" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script type="text/javascript" language="javascript">
        function GridView_SelectUnSelect(IsChecked) {
            var myCheckBox = document.getElementsByName('cb_SelectedRow');
            for (i = 0; i < myCheckBox.length; i++) {
                myCheckBox[i].checked = IsChecked;
            }
        }
        function ShowHide(CurrentObj) {
            var _CurrentObj = document.getElementById(CurrentObj);
            if (_CurrentObj.style.display == 'none') {
                _CurrentObj.style.display = 'block'
            }
            else {
                _CurrentObj.style.display = 'none'
            }
        }
        function WriteUploadedFiles() {
            var _exts = document.getElementById('hf_UploadExtList').value;
            var _extArray = new Array();
            _extArray = _exts.split(';');

            var _ResultWrapper = document.getElementById('div_UploadResults');
            var _InputWrapper = document.getElementById('div_UploadWrapper');
            var _Inputs = _InputWrapper.getElementsByTagName("input");
            var _Input = _Inputs[0];

            var _AllowUpload = false;
            for (i = 0; i < _extArray.length; i++) {
                if (_extArray[i].toLowerCase() == _Input.value.substring(_Input.value.lastIndexOf(".") + 1).toLowerCase()) {
                    _AllowUpload = true;
                }
            }
            if (_AllowUpload) { _ResultWrapper.innerHTML += "<font color='green'>" + _Input.value + " - File uploaded successfully</font><br />"; }
            else { _ResultWrapper.innerHTML += "<font color='red'>" + _Input.value + " - Extension not allowed</font><br />"; }
            _Inputs[1].style.color = '#000000';
        }
        function ClearUploadedFiles() {
            var _ResultWrapper = document.getElementById('div_UploadResults');
            var _InputWrapper = document.getElementById('div_UploadWrapper');
            var _Inputs = _InputWrapper.getElementsByTagName("input");
            _Inputs[1].style.backgroundColor = '#ffffff';
            _Inputs[1].style.color = '#ffffff';
            _ResultWrapper.innerHTML = "";
        }   
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="SiteFox_Left" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="SiteFox_Title" Runat="Server">
    <asp:Label ID="lab_Title" runat="server" CssClass="content-header-title" Text="<%$ Resources:dcCommon, dc_FileManager %>" />
    <asp:UpdatePanel ID="up_Title" runat="server" class="content-header-actions">
        <ContentTemplate>
            <asp:ImageButton ID="imb_GoUp" runat="server" ImageUrl="~/System/Design/ico/24x24/folder_out.png" onclick="imb_GoUp_Click" ToolTip="<%$ Resources:dcCommon, dc_Up %>" />
            <div class="separator"></div>
            <asp:ImageButton ID="imb_Upload" runat="server" ImageUrl="~/System/Design/ico/24x24/folder_up.png" OnClientClick="ShowHide('pan_Upload');" ToolTip="<%$ Resources:dcCommon, dc_Upload %>" />
            <asp:ImageButton ID="imb_NewFolder" runat="server" ImageUrl="~/System/Design/ico/24x24/folder_new.png" onclick="imb_NewFolder_Click" ToolTip="<%$ Resources:dcCommon, dc_CreateNewFolder %>" />
            <asp:ImageButton ID="imb_Delete" runat="server" ImageUrl="~/System/Design/ico/24x24/document_delete.png" onclick="imb_Delete_Click" ToolTip="<%$ Resources:dcCommon, dc_Delete %>" />
            <asp:ImageButton ID="imb_Move" runat="server" ImageUrl="~/System/Design/ico/24x24/document_out.png" onclick="imb_Move_Click" ToolTip="<%$ Resources:dcCommon, dc_Move %>" />
            <asp:ImageButton ID="imb_Copy" runat="server" ImageUrl="~/System/Design/ico/24x24/documents.png" onclick="imb_Copy_Click" ToolTip="<%$ Resources:dcCommon, dc_Copy %>" />
            <asp:ImageButton ID="imb_NewDoc" runat="server" ImageUrl="~/System/Design/ico/24x24/document_new.png" onclick="imb_NewFile_Click" ToolTip="<%$ Resources:dcCommon, dc_CreateNewDocument %>" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="SiteFox_Main" Runat="Server">
    <asp:UpdatePanel ID="up_Content" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:Label ID="lab_SelectedPath" runat="server" Text="" Font-Size="14px" />
            <asp:GridView ID="gv_Files" runat="server" CssClass="gridview" AutoGenerateColumns="false" RowStyle-CssClass="gridview-row" SelectedRowStyle-CssClass="selected" ShowHeader="true" 
                GridLines="None" HeaderStyle-CssClass="gridview-header">
                <Columns>
                    <asp:BoundField DataField="Id" ItemStyle-HorizontalAlign="Right" ItemStyle-Width="25px"/>
                    <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="30px">
                        <HeaderTemplate>
                            <input type="checkbox" id="cb_SelectUnSelect" onclick="GridView_SelectUnSelect(this.checked);" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="cb_SelectedRow" runat="server" ClientIDMode="Static" name="cb_SelectedRow" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="30px" >
                        <ItemTemplate>
                            <asp:Image runat="server" ImageUrl='<%# Eval("IconPath") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="<%$ Resources:dcCommon, dc_Name %>" HeaderStyle-HorizontalAlign="Left">
                        <ItemTemplate>
                            <asp:LinkButton ID="lib_Name" runat="server" OnClick="lib_Name_Click" CommandArgument='<%# Eval("Name") %>' Text='<%# Eval("Name") %>' ToolTip='<%# Eval("Name") %>' />
                            <asp:Label ID="lab_Type" runat="server" Text='<%# Eval("Type") %>' Visible="false" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Extension" HeaderText="<%$ Resources:dcCommon, dc_Extension %>" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px"/>
                    <asp:BoundField DataField="Lenght" HeaderText="<%$ Resources:dcCommon, dc_Size %>" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" ItemStyle-Width="100px"/>
                    <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-Width="60px">
                        <ItemTemplate>
                            <asp:HyperLink ID="hl_GoLive" runat="server" Visible='<%# Eval("ViewAsPage") %>' CssClass="gridview-btn-golive" NavigateUrl='<%# Eval("ViewAsPagePath") %>' Target="_blank" />
                            <asp:LinkButton ID="hl_Edit" runat="server" Visible='<%# Eval("ViewAsCode") %>' CssClass="gridview-btn-edit" OnClientClick='<%# Eval("ViewAsCodePath") %>'/>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <ucc:MessageBox ID="ucc_MessageBox" runat="server" Text="" Visible="false" />
            <asp:Panel ID="pan_Background" runat="server" CssClass="background" Visible="false"></asp:Panel>
            <asp:Panel ID="pan_NewFolder" runat="server" CssClass="actionpanel" Visible="false">
                <div class="actionpanel-header">
                    <asp:Label ID="lab_NewFolder_Title" runat="server" Text="<%$ Resources:dcCommon, dc_CreateNewFolder %>" />
                    <asp:LinkButton ID="lib_NewFolder_Close" runat="server" CssClass="actionpanel-header-close" onclick="lib_NewFolder_Close_Click" />
                </div>
                <div class="actionpanel-content">
                    <ucc:SinglelineText ID="ucc_NewFolder_Name" runat="server" dcIsReq="true" dcReadOnly="false" dcTitle="<%$ Resources:dcCommon, dc_Name %>" dcValueMaxLength="30" />
                    <asp:LinkButton ID="lib_NewFolder_Create" runat="server" CssClass="LinkButton" Text="<%$ Resources:dcCommon, dc_Create %>" ValidationGroup="mainValGroup" onclick="lib_NewFolder_Create_Click" />
                </div>
            </asp:Panel>
            <asp:Panel ID="pan_CopyOrMove" runat="server" CssClass="actionpanel" Visible="false">
                <div class="actionpanel-header">
                    <asp:Label ID="lab_CopyOrMove_Title" runat="server" Text="" />
                    <asp:LinkButton ID="lib_CopyOrMove_Close" runat="server" CssClass="actionpanel-header-close" onclick="lib_CopyOrMove_Close_Click" />
                </div>
                <div class="actionpanel-content">
                    <div style="height: 350px; width: 100%; display: block; overflow: auto;">
                        <ucc:FileManager_TreeView ID="ucc_FileManager_TreeView" runat="server" RootPath="~/Web" ShowFiles="false" />
                    </div>
                    <ucc:Boolean ID="ucc_CopyOrMove_Overwrite" runat="server" Title="<%$ Resources:dcCommon, dc_OverwriteExistingContent %>" />
                    <div class="FieldTemplates_Row">
                        <asp:Label ID="lab_CopyOrMove_MessageText" runat="server" CssClass="LabelMessageValue" Text=""></asp:Label> 
                    </div>
                    <asp:LinkButton ID="lib_CopyOrMove_DoAction" runat="server" CssClass="LinkButton" Text="" ValidationGroup="mainValGroup" onclick="lib_CopyOrMove_DoAction_Click" />
                    <asp:LinkButton ID="lib_CopyOrMove_ShowDetails" runat="server" CssClass="Link" ValidationGroup="mainValGroup" 
                        onclick="lib_CopyOrMove_ShowDetails_Click" Visible="false" Text="<%$ Resources:dcCommon, dc_ShowDetails %>" />
                </div>
            </asp:Panel>
            <asp:Panel ID="pan_Delete" runat="server" CssClass="actionpanel" Visible="false">
                <div class="actionpanel-header">
                    <asp:Label ID="lab_Delete_Title" runat="server" Text="<%$ Resources:dcCommon, dc_Delete %>" />
                    <asp:LinkButton ID="lib_Delete_Close" runat="server" CssClass="actionpanel-header-close" onclick="lib_Delete_Close_Click" />
                </div>
                <div class="actionpanel-content">
                    <ucc:MessageText ID="ucc_Delete_Text" runat="server" Title="" Value="<%$ Resources:dcCommon, dc_ConfirmDeleting %>" />
                    <asp:LinkButton ID="lib_Delete_Ok" runat="server" CssClass="LinkButton" Text="<%$ Resources:dcCommon, dc_Confirm %>" ValidationGroup="mainValGroup" onclick="lib_Delete_Ok_Click" />
                </div>
            </asp:Panel>
            <asp:Panel ID="pan_Result" runat="server" CssClass="actionpanel" Visible="false">
                <div class="actionpanel-header">
                    <asp:Label ID="lab_Result_Title" runat="server" Text="<%$ Resources:dcCommon, dc_Result %>" />
                    <asp:LinkButton ID="lib_Result_Close" runat="server" CssClass="actionpanel-header-close" onclick="lib_Result_Close_Click" />
                </div>
                <div class="actionpanel-content">
                    <div style="height: 350px; width: 100%; display: block; overflow: auto;">
                        <asp:GridView ID="gw_Result" runat="server" CssClass="GridView" AutoGenerateColumns="false" RowStyle-CssClass="GridViewRow"
                            SelectedRowStyle-CssClass="GridViewSelectedRow" ShowHeader="true" GridLines="None">
                            <Columns>
                                <asp:TemplateField ItemStyle-Width="8%" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Image ID="img_Result" runat="server" ImageUrl='<%# "~/System/Design/ico/16x16/actionDone_" + Eval("Status").ToString() + ".png" %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="FileName" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="46%"/>
                                <asp:BoundField DataField="Message" ItemStyle-HorizontalAlign="Left" ItemStyle-Width="46%"/>
                            </Columns>
                        </asp:GridView>
                    </div>
                </div>
            </asp:Panel>
            <asp:Panel ID="pan_NewFile" runat="server" CssClass="actionpanel" Visible="false">
                <div class="actionpanel-header">
                    <asp:Label ID="lab_NewFile_Title" runat="server" Text="<%$ Resources:dcCommon, dc_NewFile %>" />
                    <asp:LinkButton ID="lib_NewFile_Close" runat="server" CssClass="actionpanel-header-close" onclick="lib_NewFile_Close_Click" />
                </div>
                <asp:Panel ID="pan_NewFile_Ext" runat="server" Visible="false" CssClass="actionpanel-content">
                    <asp:DataList ID="DataList_NewFile" runat="server" HorizontalAlign="Center" RepeatColumns="5" CellSpacing="2" RepeatDirection="Horizontal" 
                        Width="100%" ItemStyle-Height="60" ItemStyle-Width="120" ItemStyle-BorderColor="White" ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="2" SelectedItemStyle-BorderColor="Red" 
                        SelectedItemStyle-BorderStyle="Dashed" SelectedItemStyle-BorderWidth="2" onitemcommand="DataList_NewFile_ItemCommand">
                        <ItemTemplate>
                            <asp:ImageButton ID="imb_Icon" runat="server" ImageUrl='<%# Eval("BigIconUrl") %>' CommandName="Select" /><br />
                            <asp:Label ID="lb_ExtName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                            <asp:Label ID="lb_Ext" runat="server" Text='<%# Eval("Ext") %>' Visible="false"></asp:Label>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:DataList>
                    <asp:HiddenField ID="hf_NewFile_ExtType" runat="server" Value="" />
                    <asp:HiddenField ID="hf_NewFile_Ext" runat="server" Value="" />
                    <asp:LinkButton ID="lib_NewFile_Next" runat="server" CssClass="LinkButton" Text="<%$ Resources:dcCommon, dc_Next %>" ValidationGroup="mainValGroup" 
                        onclick="lib_NewFile_Next_Click" Visible="false" />
                </asp:Panel>
                <asp:Panel ID="pan_NewFile_Info" runat="server" Visible="false" CssClass="actionpanel-content" Height="500">
                    <ucc:SinglelineText ID="ucc_NewFile_Name" runat="server" IsReq="true" Title="<%$ Resources:dcCommon, dc_Name %>" ValueMaxLength="50" />
                    <ucc:SinglelineText ID="ucc_NewFile_PageTitle" runat="server" IsReq="true" Title="<%$ Resources:dcCommon, dc_PageTitle %>" ValueMaxLength="50" Visible="false" />
                    <asp:Panel ID="pan_NewFile_UseMasterPage" runat="server" CssClass="FieldTemplates_Row" Visible="false">
                        <asp:Label ID="lab_NewFile_UseMasterPage_Title" runat="server" CssClass="Label" Text="<%$ Resources:dcCommon, dc_UseMasterPage %>"></asp:Label>
                        <asp:CheckBox ID="cb_NewFile_UseMasterPage_Value" runat="server" CssClass="CheckBox" Text="" AutoPostBack="true" 
                            oncheckedchanged="cb_NewFile_UseMasterPage_Value_CheckedChanged" />
                    </asp:Panel>
                    <ucc:HyperLink ID="ucc_NewFile_MasterPagePath" runat="server" FileFilter="master" RootPath="~/Web" ShowFiles="true" 
                        Title="<%$ Resources:dcCommon, dc_MasterPagePath %>" Visible="false" IsReq="false" />
                    <ucc:Boolean ID="ucc_NewFile_UseWpZone" runat="server" Title="<%$ Resources:dcCommon, dc_UseWebPartZone %>" Visible="false" />
                    <ucc:Boolean ID="ucc_NewFile_UseNavigation" runat="server" Title="<%$ Resources:dcCommon, dc_UseNavigation %>" Visible="false" />
                    <asp:LinkButton ID="lib_NewFile_Create" runat="server" CssClass="LinkButton" Text="<%$ Resources:dcCommon, dc_Create %>" ValidationGroup="mainValGroup" 
                        onclick="lib_NewFile_Create_Click" />
                </asp:Panel>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
    <div id="pan_Upload" class="actionpanel" style="display: none">
        <div class="actionpanel-header">
            <asp:UpdatePanel ID="up_Upload" runat="server">
                <ContentTemplate>
                    <asp:Label ID="lab_Upload_Title" runat="server" Text="<%$ Resources:dcCommon, dc_Upload %>" />
                    <asp:ImageButton ID="imb_Upload_Close" runat="server" CssClass="ActionPanel_Close" ImageUrl="~/System/Design/ico/24x24/delete.png" OnClientClick="ShowHide('pan_Upload'); ClearUploadedFiles();" onclick="imb_Upload_Close_Click" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        <div class="actionpanel-content">
            <div id="div_UploadWrapper">
                <asp:AsyncFileUpload ID="afu_Upload" runat="server" onuploadedcomplete="afu_Upload_UploadedComplete" OnClientUploadComplete="WriteUploadedFiles" />
            </div>
            <div id="div_UploadResults" style="height: auto; margin-top: 10px; font-weight: bold;"></div>
            <asp:HiddenField ID="hf_UploadExtList" runat="server" ClientIDMode="Static" />
        </div>
    </div>
</asp:Content>

